package sanrenxing.dayEnd.backRepertoryTotal.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sanrenxing.dayEnd.backRepertoryTotal.dao.FinancialsecuritiesDao;
import sanrenxing.dayEnd.backRepertoryTotal.dao.SecuritiesInformationDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ExchangeVarietyRate;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Financialsecurities;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Stocksector;
import sanrenxing.dayEnd.backRepertoryTotal.service.FinancialsecuritiesBiz;

import java.util.HashMap;
import java.util.List;

/**
 * 功能：证券业务层实现类
 * 编写者：蒋玲苹
 * 日期：
 * 版本：1.0
 */
@Service
public class FinancialsecuritiesBizImpl implements FinancialsecuritiesBiz {
    @Autowired
    private FinancialsecuritiesDao financialsecuritiesDao;
    //注入债券dao对象
    @Autowired
    private SecuritiesInformationDao securitiesInformationDao;
    /**
     * 添加数据
     * @param financialsecurities
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(Financialsecurities financialsecurities) {
        return financialsecuritiesDao.add(financialsecurities);
    }

    /**
     * 删除数据
     * @param seId
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int delete(String seId) {
        //判断是否为批量删除
        if(seId.contains(",")){
            //对现金账户编号按“，”分割
            String[] strs=seId.split(",");
            //循环删除
            for(String str:strs){
                //调用方法删除证券
                financialsecuritiesDao.delete(str);
                //调用删除债券的方法
                securitiesInformationDao.delete(str);
                //financialsecuritiesDao.deletes(str);
            }
            //返回1
            return 1;
        }
        //调用删除债券的方法
        securitiesInformationDao.delete(seId);
        //financialsecuritiesDao.deletes(seId);
        //调用删除证券的方法
        return financialsecuritiesDao.delete(seId);
    }

    @Override
    public List<ExchangeVarietyRate> ex() {
        return financialsecuritiesDao.ex();
    }

    @Override
    public List<Stocksector> sr() {
        return financialsecuritiesDao.sr();
    }

    /**
     * 修改数据
     *
     * @param financialsecurities
     * @return 0:修改失败,1:修改成功
     */
    @Override
    public int update(Financialsecurities financialsecurities) {
        return financialsecuritiesDao.update(financialsecurities);
    }

    /**
     * 分页查询所有数据
     *
     * @param financialsecurities
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<Financialsecurities> queryAll(Financialsecurities financialsecurities, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("financialsecurities",financialsecurities);
        map.put("start",page);
        map.put("end",(page+row));
        return financialsecuritiesDao.queryAll(map);
    }

    /**
     * 统计记录数
     *
     * @param financialsecurities
     * @return
     */
    @Override
    public int count(Financialsecurities financialsecurities) {
        return financialsecuritiesDao.count();
    }
}
